Ext.onReady(function(){ 
var sm = new Ext.grid.CheckboxSelectionModel();
var cm=new Ext.grid.ColumnModel([ 
sm,
new Ext.grid.RowNumberer({header: "编号",width:40}),
{header:'流水号',dataIndex:'serialNo',hidden:true},
{header:'姓名',dataIndex:'managerName',width:100},
{header:'职务',dataIndex:'jobtitle',width:120},
{header:'性别',dataIndex:'sexType',width:50},
{header:'证件类型',dataIndex:'idtype',width:120},
{header:'证件号码',dataIndex:'managerId',width:120},
{header:'我行对私客户',dataIndex:'isPrivateCust',width:120},
]); 
var ds=new Ext.data.Store({ 
proxy:new Ext.data.HttpProxy({
url:'customer/listManager.do',
method:'POST'
}), 
reader:new Ext.data.JsonReader({ },[
{name:'serialNo'},
{name:'managerName'},
{name:'jobtitle'}, 
{name:'sexType'},  
{name:'idtype'},  
{name:'managerId'},  
{name:'isPrivateCust'},  
]) 
}); 
ds.load({params:{start:0,limit:10}}); 

var yesOrNoStore=new Ext.data.Store({ 
proxy:new Ext.data.HttpProxy({
url:'showType.do?type=YesNo',
method:'GET'
}), 
reader:new Ext.data.JsonReader({ },[
{name:'name'}, 
{name:'code'}
]) 
}); 
yesOrNoStore.load();

var hasOrNotStore=new Ext.data.Store({ 
	proxy:new Ext.data.HttpProxy({
	url:'showType.do?type=HasOrNot',
	method:'GET'
	}), 
	reader:new Ext.data.JsonReader({ },[
	{name:'name'}, 
	{name:'code'}
	]) 
	}); 
	hasOrNotStore.load();

var addPositionStore=new Ext.data.Store({ 
	proxy:new Ext.data.HttpProxy({
	url:'showType.do?type=Position',
	method:'GET'
	}), 
	reader:new Ext.data.JsonReader({ },[
	{name:'name'}, 
	{name:'code'}
	]) 
	}); 
	addPositionStore.load();

var addSexStore=new Ext.data.Store({ 
proxy:new Ext.data.HttpProxy({
url:'showType.do?type=SexType',
method:'GET'
}), 
reader:new Ext.data.JsonReader({ },[
{name:'name'}, 
{name:'code'}
]) 
}); 
addSexStore.load();

var addNationalityStore=new Ext.data.Store({ 
proxy:new Ext.data.HttpProxy({
url:'showType.do?type=CountryCode',
method:'GET'
}), 
reader:new Ext.data.JsonReader({ },[
{name:'name'}, 
{name:'code'}
]) 
}); 
addNationalityStore.load();

var addEducationStore=new Ext.data.Store({ 
proxy:new Ext.data.HttpProxy({
url:'showType.do?type=Education',
method:'GET'
}), 
reader:new Ext.data.JsonReader({ },[
{name:'name'}, 
{name:'code'}
]) 
}); 
addEducationStore.load();

var addCertStore=new Ext.data.Store({ 
proxy:new Ext.data.HttpProxy({
url:'showType.do?type=CertType',
method:'GET'
}), 
reader:new Ext.data.JsonReader({ },[
{name:'name'}, 
{name:'code'}
]) 
}); 
addCertStore.load();

var grid=new Ext.grid.GridPanel({ 
id:'myCustomers',
renderTo:"customer_list", 
stripeRows:true,//斑马线效果
title:"高管列表", 
height:500, 
cm:cm,
store: ds,
loadMask: { msg: "加载中..." }, 
viewConfig: {   
                            forceFit:true   
            },   
            bbar: new Ext.PagingToolbar({   
                pageSize: 10,   
                store: ds, 
                displayInfo: true,   
                displayMsg: '第{0} 到 {1} 条数据 共{2}条',   
                emptyMsg: "没有数据"   
            }),
 tbar: [
 {text:'新增',id: 'btnAdd'},
 '-',
 {text:'查看/编辑',handler:checkMyCustomer},
 '-',
 {text:'删除',handler:deleteCustomer}
 ]              
});

//新增客户表单
addForm = new Ext.form.FormPanel({ 
id: 'addCustomerForm', 
width: 580, 
height: 570, 
//样式 
bodyStyle: 'margin:3px 3px 3px 3px', 
frame: true, 
xtype: 'filedset', 
labelWidth: 100, 
items: 
[ { xtype: 'fieldset', 
title: '高管信息', 
collapsible: true, 
autoHeight: true, 
autoWidth: true, 
items: 
[
{layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
xtype: 'textfield',
id: 'managerName', 
name: 'managerName', 
fieldLabel: '高管姓名', 
emptyText: '必填', 
blankText: '高管姓名不能为空', 
allowBlank: false,  
width:130
}]},
     {  columnWidth : .5, 	      	   
	 layout : "form",
           items : [{
      xtype: 'combo', 
 id : "jobtitle",
              store :addPositionStore,
              fieldLabel: '职务',
              valueField : 'code',
              displayField : 'name',
              emptyText : '请选择职务...',
              allowBlank : false,
              blankText:'请选择职务',
              editable: false,
              typeAhead : true,
              width: 130,
              mode:'remote',  
              hiddenName:'jobtitle',
              triggerAction : 'all',
              selectOnFocus : true
}]} 
]},

{layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
xtype: 'combo', 
 id : "sexType",
              store :addSexStore,
              fieldLabel: '性别',
              valueField : 'code',
              displayField : 'name',
              emptyText : '请选择性别...',
              editable: false,
              typeAhead : true,
              allowBlank : false,
              width: 130,
              mode:'remote',  
              hiddenName:'sexType',
              triggerAction : 'all',
              selectOnFocus : true
}]},
     {  columnWidth : .5, 	      	   
	 layout : "form",
           items : [{
xtype: 'datefield',
id: 'birthday', 
name: 'birthday', 
fieldLabel: '生日',  
allowBlank: true, 
editable:false, 
width:130 ,
format : 'Y-m-d'
}]} 
]},


{layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
xtype: 'combo', 
 id : "nationality",
              store :addNationalityStore,
              fieldLabel: '国籍',
              valueField : 'code',
              displayField : 'name',
              emptyText : '请选择国籍...',
              editable: false,
              typeAhead : true,
              width: 130,
              mode:'remote',  
              hiddenName:'nationality',
              triggerAction : 'all',
              selectOnFocus : true
}]},
     {  columnWidth : .5, 	      	   
	 layout : "form",
           items : [{
xtype: 'combo', 
 id : "education",
              store :addEducationStore,
              fieldLabel: '学历',
              valueField : 'code',
              displayField : 'name',
              emptyText : '请选择学历...',
              editable: false,
              typeAhead : true,
              width: 130,
              mode:'remote',  
              hiddenName:'education',
              triggerAction : 'all',
              selectOnFocus : true
}]} 
]},
{layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
        	  xtype: 'combo', 
 			  id : "idtype",
              store :addCertStore,
              fieldLabel: '证件类型',
              valueField : 'code',
              displayField : 'name',
              emptyText : '请选择证件类型...',
              allowBlank : false,
              blankText:'请选择证件类型',
              editable: false,
              typeAhead : true,
              width: 130,
              mode:'remote',  
              hiddenName:'idtype',
              triggerAction : 'all',
              selectOnFocus : true
}]},
     {  columnWidth : .5, 	      	   
	 layout : "form",
           items : [{
xtype: 'textfield',
id: 'managerId', 
name: 'managerId', 
fieldLabel: '证件号码', 
emptyText: '必填', 
blankText: '证件号码不能为空', 
allowBlank: false,  
width:130
}]} 
]},
{
layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
xtype: 'textfield',
id: 'telNo', 
name: 'telNo', 
fieldLabel: '电话',
allowBlank: true,  
nanText:'请输入有效整数',           //无效数字提示  
width: 130 
}]},{ columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
xtype: 'textfield',
id: 'faxNo', 
name: 'faxNo', 
fieldLabel: '传真',
allowBlank: true,    
width: 130 
}]} 
]},

{
layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
xtype: 'textfield',
id: 'cellNo', 
name: 'cellNo', 
fieldLabel: '手机号码',
allowBlank: true,  
width: 130 
}]},{ columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
        	   xtype: 'textfield',
        	   id: 'email', 
        	   name: 'email', 
        	   fieldLabel: '电子邮箱',  
        	   allowBlank: true,  
        	   width:130
}]} 
]},

{ layout : "form",
           items : [{
xtype: 'hidden', 
 id : "serialNo",
              fieldLabel: '地址ID',
              allowBlank: true
}]},{
	layout:"column",
	items:[{
		columnWidth : .5, // 该列有整行中所占百分比
	    layout : "form",
	    items : [{
			xtype: 'textfield',
			id: 'companyWorkTime', 
			name: 'companyWorkTime', 
			fieldLabel: '企业任职年限(年)',
            allowBlank : false,
			width: 130 
	    }]},{ 
	    columnWidth : .5, // 该列有整行中所占百分比
	    layout : "form",
	    items : [{
			xtype: 'textfield',
			id: 'careerWorkTime', 
			name: 'careerWorkTime', 
			fieldLabel: '从业年限(年)',
			allowBlank: true,  
			width: 130 
	}]} 
	]},{
		layout:"column",
		items:[{
			columnWidth : .5, // 该列有整行中所占百分比
		    layout : "form",
		    items : [{
		    	  xtype: 'combo', 
	 			  id : "badCreditRecord",
	              store :hasOrNotStore,
	              fieldLabel: '有无不良信用记录',
	              valueField : 'code',
	              displayField : 'name',
	              allowBlank : false,
	              editable: false,
	              typeAhead : true,
	              width: 130,
	              mode:'remote',  
	              hiddenName:'badCreditRecord',
	              triggerAction : 'all',
	              selectOnFocus : true
		    }]},{ 
		    columnWidth : .5, // 该列有整行中所占百分比
		    layout : "form",
		    items : [{
		    	  xtype: 'combo', 
	 			  id : "badDebtWorkRecord",
	              store :yesOrNoStore,
	              fieldLabel: '曾任职逃废债企业',
	              valueField : 'code',
	              displayField : 'name',
	              allowBlank : false,
	              editable: false,
	              typeAhead : true,
	              width: 130,
	              mode:'remote',  
	              hiddenName:'badDebtWorkRecord',
	              triggerAction : 'all',
	              selectOnFocus : true
		}]} 
		]},{
			layout:"column",
			items:[{
				columnWidth : .5, // 该列有整行中所占百分比
			    layout : "form",
			    items : [{
			    	  xtype: 'combo', 
		 			  id : "isPrivateCust",
		              store :yesOrNoStore,
		              fieldLabel: '我行对私客户',
		              valueField : 'code',
		              displayField : 'name',
		              allowBlank : true,
		              editable: false,
		              typeAhead : true,
		              width: 130,
		              mode:'remote',  
		              hiddenName:'isPrivateCust',
		              triggerAction : 'all',
		              selectOnFocus : true,
		              listeners:{  	        	   
			        	   select : function(combo, record,index){
			    				if(combo.value == '0')Ext.getCmp("privateCustNo").setVisible(false);
			    				else if (combo.value == '1')Ext.getCmp("privateCustNo").setVisible(true);
								
							} 
			           }
			    }]},{ 
			    columnWidth : .5, // 该列有整行中所占百分比
			    layout : "form",
			    items : [{
			    	xtype: 'textfield',
					id: 'privateCustNo', 
					name: 'privateCustNo', 
					fieldLabel: '客户号',
					allowBlank: true,
					hidden: true,
					width: 130,
					
			}]} 
			]},{
			layout : "form",
		    items : [{
				xtype: 'textarea',
				id: 'intro', 
				name: 'intro', 
				fieldLabel: '简介',
				allowBlank: true, 
				hidden:true,
				width: 400 
		    }]
		},{
			layout : "form",
		    items : [{
				xtype: 'textarea',
				id: 'careerInfo', 
				name: 'careerInfo', 
				fieldLabel: '工作经历',
				allowBlank: true,  
				width: 400 
		    }]
		},{
			layout : "form",
		    items : [{
				xtype: 'textarea',
				id: 'educationInfo', 
				name: 'educationInfo', 
				fieldLabel: '教育经历',
				allowBlank: true,  
				width: 400 
		    }]
		},{
			layout : "form",
		    items : [{
				xtype: 'textarea',
				id: 'holdInfo', 
				name: 'holdInfo', 
				fieldLabel: '持股情况',
	              allowBlank : false, 
				width: 400 
		    }]
		},{
			layout : "form",
		    items : [{
				xtype: 'textarea',
				id: 'familyInfo', 
				name: 'familyInfo', 
				fieldLabel: '家庭情况',
				hidden:true,
				allowBlank: true,  
				width: 400 
		    }]
		}
	
	
]}]});

//新增用户窗口 
addWin = new Ext.Window({ 
id: 'addCustomerWin', 
title: '客户基本信息-高管信息', 
width: 600, 
height: 550, 
//背景遮罩 
modal: true, 
//重置大小 
resizable: false, 
//当关闭按钮被点击时执行的动作 
closeAction: 'hide', 
plain: true, 
buttonAlign: 'right', 
items:addForm, 
buttons: 
[  
{ text: '保存', id: 'btnSubmit' } ,
{ text: '关闭', handler: function() { Ext.getCmp('addCustomerWin').hide(); } }

] 
});

var config={
    title:"提示",
    width:240,
    msg:'<div align="center">操作成功！</div>',
    closable:false,
    buttons:{cancel:'取消',yes:'下一步',no:'继续添加'},
    fn: function(btn){
    	if(btn == 'yes'){
    		window.location.href = "view/customer/Customer_Stockholder.jsp";
    	}
    	else if(btn == 'no'){
    		btnAddClick();
    	}
    }
    //icon:Ext.MessageBox.Question
}

function addRoleFunction() {

	
	var addForm = Ext.getCmp("addCustomerForm");

if(addForm.form.isValid()){
	 addForm.form.doAction('submit', { 

                    url : 'customer/addManager.do', 
 
                    method : 'post', 
 
                       
                       success : function() { 

                       var msgbox = Ext.MessageBox.show(config); 
								Ext.getCmp('addCustomerWin').hide(); 
                       Ext.getCmp('myCustomers').store.reload();
                       //Ext.Msg.alert('提示', '保存成功！'); 
 
                       }, 
                        failure : function(form, action) { 

                           Ext.Msg.alert('提示', '保存未成功！'); 
 
                        } 
                    });  
                    }
 }
  


//添加按钮单击事件 
function btnAddClick() { 
Ext.getCmp("addCustomerWin").show();
addForm.getForm().getEl().dom.reset(); 
Ext.getCmp("addCustomerWin").hide(); 

Ext.getCmp("addCustomerWin").buttons[0].handler = addRoleFunction; 
Ext.getCmp("addCustomerWin").show(); 
}; 

//新增按钮 
var addUserBtn = Ext.getCmp('btnAdd'); 
addUserBtn.on('click', btnAddClick); 

//删除地址
function deleteCustomer(){
var grid = Ext.getCmp('myCustomers'); 
if (grid.getSelectionModel().getSelections()[0] == undefined) { 
Ext.Msg.alert("提示", "请选中要删除的项！"); 
} 
else{
Ext.MessageBox.confirm('提示', '确实要删除所选的项吗？', deleteConfirm);
}
}

function deleteConfirm(btn){
if (btn == 'yes') {
//alert(grid.getSelectionModel().getSelections()[0].data.serialNo);
 Ext.Ajax.request({
  url:'customer/deleteManager.do',
  params : { serialNo: grid.getSelectionModel().getSelections()[0].data.serialNo},
  method:'POST',
  success:function(){
   Ext.MessageBox.alert("提示","删除成功！");
   Ext.getCmp('myCustomers').store.reload(); 
  },failure:function(){
    Ext.MessageBox.alert("提示", "删除失败！"); 
  }
});
}
}

function checkMyCustomer(){
if (grid.getSelectionModel().getSelections()[0] == undefined) { 
Ext.Msg.alert("提示", "请选中要查看的客户！"); 
}
else{
		var serialNo = grid.getSelectionModel().getSelections()[0].data.serialNo;
	
	Ext.getCmp('addCustomerForm').form.reset(); 
	Ext.getCmp("addCustomerWin").buttons[0].handler = editAddressFunction; 
	
           Ext.Ajax.request({
url:'customer/getManager.do',
params : { serialNo: grid.getSelectionModel().getSelections()[0].data.serialNo},
method:'POST',
   success:function(response){

 var addJSON = Ext.util.JSON.decode(response.responseText);

 	Ext.getCmp("addCustomerWin").show();
  	Ext.getCmp("serialNo").setValue(addJSON.serialNo);  
	Ext.getCmp("managerName").setValue(addJSON.managerName);
  	Ext.getCmp("jobtitle").setValue(addJSON.jobtitle);
  	Ext.getCmp("sexType").setValue(addJSON.sexType);
  	Ext.getCmp("education").setValue(addJSON.education);
   	Ext.getCmp("nationality").setValue(addJSON.nationality);
   	Ext.getCmp("idtype").setValue(addJSON.idtype);
   	Ext.getCmp("managerId").setValue(addJSON.managerId);
	Ext.getCmp("telNo").setValue(addJSON.telNo);
	Ext.getCmp("birthday").setValue(addJSON.birthday);
  	Ext.getCmp("cellNo").setValue(addJSON.cellNo);
  	Ext.getCmp("faxNo").setValue(addJSON.faxNo);
  	Ext.getCmp("email").setValue(addJSON.email);
  	Ext.getCmp("companyWorkTime").setValue(addJSON.companyWorkTime);
  	Ext.getCmp("careerWorkTime").setValue(addJSON.careerWorkTime);
  	Ext.getCmp("badCreditRecord").setValue(addJSON.badCreditRecord);
  	Ext.getCmp("badDebtWorkRecord").setValue(addJSON.badDebtWorkRecord);
  	Ext.getCmp("intro").setValue(addJSON.intro);
  	Ext.getCmp("careerInfo").setValue(addJSON.careerInfo);
  	Ext.getCmp("educationInfo").setValue(addJSON.educationInfo);
  	Ext.getCmp("holdInfo").setValue(addJSON.holdInfo);
  	Ext.getCmp("familyInfo").setValue(addJSON.familyInfo);
  	Ext.getCmp("isPrivateCust").setValue(addJSON.isPrivateCust);
  	if(addJSON.isPrivateCust == '1'){
  	  	Ext.getCmp("privateCustNo").setValue(addJSON.privateCustNo);
  	  	Ext.getCmp("privateCustNo").setVisible(true);
  	}
	
  },failure:function(){
    Ext.MessageBox.alert("请求异常！");
  }
}); 
}
}


//编辑地址
function editAddressFunction(){
	
	var addForm = Ext.getCmp("addCustomerForm");
if(addForm.form.isValid()){
	 addForm.form.doAction('submit', { 

                    url : 'customer/editManager.do', 
 
                    method : 'post', 
 
                       
                       success : function() { 

                       
                       Ext.getCmp('myCustomers').store.reload();
                       Ext.Msg.alert('提示', '保存成功！'); 
 
                       }, 
                        failure : function(form, action) { 

                           Ext.Msg.alert('提示', '保存失败！'); 
 
                        } 
                    }); 
                    }
}

function rowdblclickFn(grid, rowIndex, e){//双击事件  
             var row = grid.getStore().getAt(rowIndex); 
             var selectedCustId = row.get("custId");
             Ext.Ajax.request({
  url:'checkRequest.do',
  method:'GET',
  success:function(){
  window.location.href="checkMyCustomer.do?CustId="+selectedCustId;
  },failure:function(){
    Ext.MessageBox.alert("请求异常！");
  }
});  
           //  window.location.href="view/customer/CheckCustomer_General.jsp?custId="+selectedCustId;
        }   
        grid.addListener('rowdblclick',checkMyCustomer);
/*grid.on('rowdblclick',function(){ window.location.href="view/customer/CheckCustomer_General.jsp" });*/
}); 